package com.example.onlineeducation.viewmodel

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.example.onlineeducation.base.BaseViewModel
import com.example.onlineeducation.data.model.ExamRecordListDataModel
import com.example.onlineeducation.data.model.ScoreRecordListDataModel
import com.example.onlineeducation.repository.StudyRepository
import kotlinx.coroutines.flow.collectLatest

class ExamRecordVM : BaseViewModel() {
    private val mStudyRepository: StudyRepository by lazy { StudyRepository(mApiService) }

    
    private val _mExamRecordListDataModel = MutableLiveData<PagingData<ExamRecordListDataModel>>()
    val mExamRecordListDataModel: LiveData<PagingData<ExamRecordListDataModel>> = _mExamRecordListDataModel
    
    
    fun getExamRecordListPager(proId: String) = ycLaunch {
        mStudyRepository.getExamRecordListPager(proId).cachedIn(viewModelScope).collectLatest {
            _mExamRecordListDataModel.postValue(it)
        }
    }

    private val _mScoreRecordListDataModel = MutableLiveData<PagingData<ScoreRecordListDataModel>>()
    val mScoreRecordListDataModel: LiveData<PagingData<ScoreRecordListDataModel>> = _mScoreRecordListDataModel


    fun getScoreRecordListPager() = ycLaunch {
        mStudyRepository.getScoreRecordListPager().cachedIn(viewModelScope).collectLatest {
            _mScoreRecordListDataModel.postValue(it)
        }
    }

}
